namespace map2D {
    /**队列管理器，管理不同类型角色列表*/
	export class RoleQueueManager{
        private _roleClsDict;
        private _scene:SceneManagerBase;
        public constructor(sceneMgr:SceneManagerBase)
        {
            this._scene = sceneMgr;
            this._roleClsDict = {};
        }
        /**创建一类角色队列
         * @param roleType 角色类型，参考RoleType         
         * @param roleClass 角色类
         * @param isDepth 是否参与深度比较
        */
        public addQueue(roleType:number,roleClass:any,isDepth:boolean=true,className:string,types:string[]=null)
        {
            let s =this;            
            s._roleClsDict[roleType] = new RoleQueue<any>(roleType,roleClass,isDepth);
            PoolUtil.registerClassInfo(roleClass, className, types);            
        }
        public create(cfg:any,roleType:number,owner:map2D.IRole=null):map2D.IRole
        {
            let s= this;
            var r:map2D.IRole;		
            
            if(s._roleClsDict[cfg.roleType])
			{                
                let roleQueue:RoleQueue<any>;
                roleQueue = s._roleClsDict[roleType];                
				r = <any>PoolUtil.fromPool(roleQueue.roleClass);
				r.parseConfig(roleType, cfg);
				// r.create();
                if(owner)
                    (<map2D.IRole>r).setOwner(owner);
			}
            return r;
        }
        public removeFromSceneVec(r:map2D.IRole):void
        {
            let roleQueue:RoleQueue<any>;
            let s = this;
            roleQueue = s._roleClsDict[r.roleType];  
            if(roleQueue)
            {
                roleQueue.list.splice(r.seq, 1);
            }
        }
        public addToSceneVec(r:map2D.IRole):void
		{
            let roleQueue:RoleQueue<any>;
            let s = this;
            roleQueue = s._roleClsDict[r.roleType];  
            if(roleQueue)
            {
                roleQueue.list.push(<IRole>r);
            }
        }
        public getList(roleType:number)
        {            
            let s = this;
            return s._roleClsDict[roleType]?s._roleClsDict[roleType].list:null;
        }
        public foreachQueue(func:(queue:RoleQueue<any>)=>void,thisObj:any=null):void
        {
            let s= this;
            let roleQueue:RoleQueue<any>;
            for(let key in s._roleClsDict)
            {
                roleQueue = s._roleClsDict[key];
                func.call(thisObj,roleQueue);
            }
        }
    }
    export class RoleQueue<T>{
        public list:IRole[];
        private _roleType:number;
        // private _listType:number;
        private _roleClass:T;
        private _isDepth:boolean;
        public constructor(roleType:number,roleClass:T, isDepth:boolean=true)
        {
            let s= this;
            s._roleType = roleType;
            // s._listType = listType;
            s._roleClass = roleClass;
            s._isDepth = isDepth;
            s.list = [];
        }
        public get roleClass():T
        {
            return this._roleClass;
        }
        public get isDepth():boolean
        {
            return this._isDepth;
        }
        // public get listType():number
        // {
        //     return this._listType;
        // }
        public get roleType():number
        {
            return this._roleType;
        }
        public clearList()
        {
            let len:number;
            let s = this;
            len = s.list.length;
			while(--len>-1)			
				(<map2D.IRole>s.list[len]).clear();	
            s.list.length = 0;
        }

    }
}